broadway: Report some level of frame timings
authorAlexander Larsson <alexl@redhat.com>
Fri, 29 Mar 2019 11:31:42 +0000 (12:31 +0100)
committerAlexander Larsson <alexl@redhat.com>
Fri, 29 Mar 2019 13:30:13 +0000 (14:30 +0100)
This is not ideal because we report the time of a full roundtrip, rather
than the presentation time, but its better than nothing, and i'm not sure
how the browser time should be reconciled.

gdk/broadway/gdksurface-broadway.c
gdk/broadway/gdksurface-broadway.h

index 580f1fecf3fc7b5907f87709a5973e3fe3b6c666..732d2a7fd64c9c9e00a6453218a5f0e634aab1a7 100644 (file)
@@ -128,13 +128,32 @@ _gdk_broadway_roundtrip_notify (GdkSurface  *surface,
                                 guint32 tag,
                                 gboolean local_reply)
 {
+  GdkSurfaceImplBroadway *impl = GDK_SURFACE_IMPL_BROADWAY (surface->impl);
   GdkFrameClock *clock = gdk_surface_get_frame_clock (surface);
+  GdkFrameTimings *timings;
+
+  timings = gdk_frame_clock_get_timings (clock, impl->pending_frame_counter);
+  impl->pending_frame_counter = 0;
 
   /* If there is no remove web client, rate limit update to once a second */
   if (local_reply)
     g_timeout_add_seconds (1, (GSourceFunc)thaw_clock_cb, g_object_ref (clock));
   else
     _gdk_frame_clock_thaw (clock);
+
+  if (timings)
+    {
+      timings->refresh_interval = 33333; /* default to 1/30th of a second */
+      // This isn't quite right, since we've done a rountrip back too, can we do better?
+      timings->presentation_time = g_get_monotonic_time ();
+      timings->complete = TRUE;
+
+
+#ifdef G_ENABLE_DEBUG
+      if ((_gdk_debug_flags & GDK_DEBUG_FRAMES) != 0)
+        _gdk_frame_clock_debug_print_timings (clock, timings);
+#endif
+    }
 }
 
 static void
@@ -145,6 +164,7 @@ on_frame_clock_after_paint (GdkFrameClock *clock,
   GdkSurfaceImplBroadway *impl = GDK_SURFACE_IMPL_BROADWAY (surface->impl);
   GdkBroadwayDisplay *broadway_display;
 
+  impl->pending_frame_counter = gdk_frame_clock_get_frame_counter (clock);
   _gdk_frame_clock_freeze (gdk_surface_get_frame_clock (surface));
 
   broadway_display = GDK_BROADWAY_DISPLAY (display);
@@ -154,6 +174,30 @@ on_frame_clock_after_paint (GdkFrameClock *clock,
   gdk_display_flush (display);
 }
 
+static void
+on_frame_clock_before_paint (GdkFrameClock *clock,
+                             GdkSurface     *surface)
+{
+  GdkFrameTimings *timings = gdk_frame_clock_get_current_timings (clock);
+  gint64 presentation_time;
+  gint64 refresh_interval;
+
+  if (surface->update_freeze_count > 0)
+    return;
+
+  gdk_frame_clock_get_refresh_info (clock,
+                                    timings->frame_time,
+                                    &refresh_interval, &presentation_time);
+  if (presentation_time != 0)
+    {
+      timings->predicted_presentation_time = presentation_time + refresh_interval;
+    }
+  else
+    {
+      timings->predicted_presentation_time = timings->frame_time + refresh_interval / 2 + refresh_interval;
+    }
+}
+
 static void
 connect_frame_clock (GdkSurface *surface)
 {
@@ -161,6 +205,8 @@ connect_frame_clock (GdkSurface *surface)
     {
       GdkFrameClock *frame_clock = gdk_surface_get_frame_clock (surface);
 
+      g_signal_connect (frame_clock, "before-paint",
+                        G_CALLBACK (on_frame_clock_before_paint), surface);
       g_signal_connect (frame_clock, "after-paint",
                         G_CALLBACK (on_frame_clock_after_paint), surface);
     }
index a89042e17ad65d3f14f69d7e5a146100995dc2f5..9be2da92df7e188b2bf8faa54dd9b48f64f81ae8 100644 (file)
@@ -61,6 +61,8 @@ struct _GdkSurfaceImplBroadway
   int pre_maximize_width;
   int pre_maximize_height;
 
+  gint64 pending_frame_counter;
+
   gboolean dirty;
   gboolean last_synced;